package com.example.jpademo.dao;

import com.example.jpademo.model.EtlApp;
import com.example.jpademo.model.EtlAppInfo;
import com.example.jpademo.vo.AppConfVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface EtlAppInfoDao extends JpaRepository<EtlAppInfo,Integer>, JpaSpecificationExecutor<EtlAppInfo> {
    /**
     * 单表基于方法简单的查询
     *
     * @param appId
     * @return
     */
    List<EtlAppInfo> findEtlAppInfoByAppId(String appId);

    /**
     * 嵌套子查询
     *
     * @param appId
     * @return
     */
    @Query("from EtlAppInfo info where info.appId in (select app.id from EtlApp app where app.id = ?1)")
    List<EtlAppInfo> selectByAppid(String appId);
    @Query(" from EtlAppInfo info where info.appId = '%'+?1+'%' order by info.appId desc ")
    List<EtlAppInfo> selectMaxId(String id,PageRequest pageRequest);

    /**
     * join查询
     *
     * @param appId
     * @return
     */
    @Query("select info from EtlAppInfo info join EtlApp app on info.appId = app.id  where app.id = ?1")
    List<EtlAppInfo> joinByAppid(String appId);
    /**
     * like查询 =
     *
     * @param appId
     * @return
     */
    @Query("select info from EtlAppInfo info join EtlApp app on info.appId = app.id  where app.id = '%'+?1+'%'")
    List<EtlAppInfo> likeByAppid(String appId);

    /**
     * like查询
     *
     * @param appId
     * @return
     */
    @Query("select info from EtlAppInfo info where  info.appId  like %?1 ")
    List<EtlAppInfo> likeByAppid1(String appId);

    /**
     * like查询
     *
     * @param appId
     * @return
     */
    @Query("select info from EtlAppInfo info where  info.appId  like ?1% ")
    List<EtlAppInfo> likeByAppid2(String appId);
    /**
     * like查询
     *
     * @param appId
     * @return
     */
    @Query("select info from EtlAppInfo info where  info.appId  like %?1% ")
    List<EtlAppInfo> likeByAppid3(String appId);
    /**
     * like查询
     *
     * @param appId
     * @return
     */
    @Query("select info from EtlAppInfo info where  info.appId  like %:appId% ")
    List<EtlAppInfo> likeByAppid4(String appId);

    /**
     * 连表查询（笛卡尔积）
     *
     * @param appId
     * @return
     */
    @Query("from EtlAppInfo info , EtlApp app where info.appId = app.id  and app.id = ?1")
    List selectMixByAppid(String appId);

    /**
     * 连表查询（笛卡尔积）
     *
     * @param appId
     * @return
     */
    @Query("from EtlAppInfo info , EtlApp app where info.appId = app.id  and app.id = :appId")
    List selectMixByAppid1(String appId);

    /**
     * 连表查询（笛卡尔积）
     *
     * @param appId
     * @return
     */
    @Query("from EtlAppInfo info , EtlApp app where info.appId = app.id  and app.id = :#{#app.id}")
    List selectMixByAppid(EtlApp app);

    /**
     * 连表查询（笛卡尔积）
     *
     * @param appId
     * @return
     */
    @Query("from EtlAppInfo info , EtlApp app where info.appId = app.id  and app.id = ?#{#app.id}")
    List selectMixByAppid1(EtlApp app);

}
